package com.rec.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.rec.entity.ConsumeLogs;

public interface ConsumeLogsRepository extends JpaRepository<ConsumeLogs, Integer>,
JpaSpecificationExecutor<ConsumeLogs>{
	@Modifying
	@Query(value="update consumelogs s set s.outtime = :outtime  where s.cardno = :cardno and s.intime =:intime",nativeQuery = true)
	Integer getOutSet(@Param("cardno")String cardno, 
			@Param("outtime")String outtime,
			@Param("intime")String intime);
	
	@Query(value="select s.intime from consumelogs s where s.cardno = :cardno",nativeQuery = true)
	List<String> getLastTime(String cardno);
	
	@Query(value="select count(id) as cardno,s.intime,s.outtime,s.readroomid as readroomid,s.id "
			+ "from consumelogs s where s.outtime <= :Daytime and s.intime>:beforeDay "
			+ "GROUP BY s.readroomid;",nativeQuery = true)
	List<ConsumeLogs> getCountDay(
			  @Param("beforeDay")String beforeDay,
			  @Param("Daytime")String Daytime);

}
